home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / StdIO / fprintf.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  2KB  |  86 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /*  fprintf.c - various ways to output formatted strings
  18.  *
  19.  *  fprintf    prints a string to a buffered output stream
  20.  *  printf     prints a formatted string to stdout
  21.  *  sprintf    prints formatted a string into a given buffer
  22.  */
  23.  
  24. #include <stdio.h>
  25.  
  26. extern int    format();
  27.  
  28. static FILE *currentStream;    /* Used by fprintf and printf */
  29. static char *bufptr;        /* Used by sprintf. */
  30.  
  31. /*
  32.  * This routine called by printf and fprintf to output one character.
  33.  */
  34.  
  35. static int
  36. output(c)
  37. unsigned int c;
  38. {
  39.     return fputc(c, currentStream);
  40. }
  41.  
  42. /*
  43.  * This routing called by sprintf to output on character to the buffer.
  44.  */
  45.  
  46. static int
  47. putone(c)
  48. unsigned int c;
  49. {
  50.     *bufptr++ = c;
  51.     return c;
  52. }
  53.  
  54. int
  55. fprintf(fp, fmt, args)
  56. FILE *fp;
  57. char *fmt;
  58. int  args;
  59. {
  60.     currentStream = fp;
  61.     return format(output, fmt, &args);
  62. }
  63.  
  64. int
  65. printf( fmt, args )
  66. char *fmt;
  67. int  args;
  68. {
  69.     currentStream = stdout;
  70.     return format(output, fmt, &args);
  71. }
  72.  
  73. int
  74. sprintf( linptr, fmt, args )
  75. char *linptr;
  76. char *fmt;
  77. int args;
  78. {
  79.     int len;
  80.  
  81.     bufptr = linptr;
  82.     len = format( putone, fmt, &args );
  83.     *bufptr = '\0';
  84.     return len;
  85. }
  86.